<template>
	<view class="main">
		<view class="name">
			领驾猫交规
		</view>
		<view class="subject">
			<view class="item" style="background:url(../../static/index_bg1.png) no-repeat center"
				@click="subject('1')">
				<view class="left">
					<view class="subject-title">
						免费
					</view>
					<view class="bottom">
						<view class="author">
							体验
						</view>
						<view class="number">
							900 多道题
						</view>
					</view>
				</view>

			</view>
			<view class="item" style="background:url(../../static/index_bg2.png) no-repeat center" @click="vipContent">
				<view class="left">
					<view class="subject-title">
						VIP
					</view>
					<view class="bottom">
						<view class="author">
							精选
						</view>
						<view class="number">
							600 多道题
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>

</template>

<script>
	import tabBar from '../../components/tabbar.vue'
	import moment from 'moment';
	import {
		userinfo
	} from "@/api/index.js"
	export default {
		data() {
			return {


			}
		},
		components: {
			tabBar
		},
		onLoad(option) {
			let key = option.key
			if (key) {
				uni.setStorageSync('lingjiamao_key', key);
			}

			this.nowDate = moment().format('YYYY年MM月DD日');

		},
		onShow() {

		},
		methods: {
			// 题目
			subject(type) {
				uni.navigateTo({
					url: "/pages/subject/subject"
				})
			},
			//vip
			vipContent() {
				userinfo().then(res => {
					this.userinfo = res.data
					let userinfo = this.userinfo
					uni.setStorageSync("userInfo", res.data)
					if (userinfo.vip == 0) {
						uni.showModal({
							title: '',
							cancelText: '取消',
							confirmText: '购买',
							content: `尊敬的用户，您的账号未购买会员，是否购买！`,
							success(res) {
								if (res.confirm) {
									uni.navigateTo({
										url: "/pages/mall/vipList"
									})
								} else if (res.cancel) {

								}
							}
						})
					} else {
						uni.navigateTo({
							url: "/pages/vip/index"
						})
					}
				})



			}
		}
	}
</script>

<style scoped lang="scss">
	.main {
		padding: 58rpx 26rpx;
		background: #fff;
	}

	.name {
		color: #fff;
		background-color: #3484FF;
		text-align: center;
		position: fixed;
		top: 0;
		left: 0;
		width: 100%;
		font-size: 28rpx;
		padding: 20rpx 0;
	}

	.subject {
		margin-top: 50rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;

		.item {
			width: 336rpx;
			height: 336rpx;
			display: flex;
			color: #fff;
			align-items: center;
			justify-content: center;
			background-size: contain;

			.left {
				.subject-title {
					font-size: 40rpx;
					font-weight: 600;
				}

				.bottom {
					display: flex;
					align-items: flex-end;

					.author {
						font-size: 34rpx;
						margin-right: 40rpx;
					}

					.number {
						font-size: 28rpx;
					}
				}

			}



		}
	}
</style>